package com.farm.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.farm.pic.Pic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;


@Slf4j
@RestController
@RequestMapping("/ai")
public class AIScanController {
    @Value("${image.basePath}")
    private String basePath;

    @PostMapping("/result")
    public String aiScan(@RequestBody String picName) throws IOException {
        Pic pic = new Pic();
        boolean result = pic.getAccessToken();
        String answer = null;
        if (result){
            answer = pic.getAnswer(basePath+picName);
        }
        return answer != null && !StringUtils.isBlank(answer) ? answer : "";
    }
}
